// 组件接口

class TextMessage {
  constructor(message) {
    this.message = message;
  }
  getText() {
    return this.message;
  }
}

function HTMLDecorator(BaseClass) {
  return class extends BaseClass {
    getText() {
      return `<p>${super.getText()}</p>`;
    }
  };
}

function EncryptDecorator(BaseClass) {
  return class extends BaseClass {
    getText() {
      return this.encrypt(super.getText());
    }
    encrypt(msg) {
      return `加密:${msg}`;
    }
  };
}

let DecoratorClass = HTMLDecorator(TextMessage);
DecoratorClass = EncryptDecorator(DecoratorClass);

const messageInstance = new DecoratorClass("Hello Typescript");
console.log(messageInstance.getText());
